import struct
import time
from coin_order_gateway_pb2 import OrderGatewayLog

t = time.time()

path = 'orders.data'
with open(path, "rb") as f:
  MAGIC = b'\x00\x31\x41\x59\x00\x01\x00\x00'

  if f.read(8) != MAGIC:
    print('magic bytes do not match')
    sys.exit(1)

  while True:
    length = f.read(8)
    if length == b'':
      break

    length = struct.unpack('<Q', length)[0]
    print('length ', length)
    _crc = f.read(4)
    _meta = f.read(32)  # q_seq, topic_id, topic_seq, timestamp
    data = f.read(length - 32)
    _crc = f.read(4)

    e = OrderGatewayLog()
    e.ParseFromString(data)

    # if e.type == OrderGatewayLog.ORDER_EVENT and e.event.symbol in SYMBOL_FILTER:
    # e.exchange_type
    # e.symbol str
    # e.internal_order_id str
    # pass

print: (t - time.time())
